#define _CRT_SECURE_NO_WARNINGS 1
int cmp(void* p1, void* p2)
{
    return *(int*)p2 - *(int*)p1;
}

int removeElement(int* nums, int numsSize, int val)
{
    int count = 0;
    for (int i = 0; i < numsSize; i++)
    {
        if (nums[i] == val)
        {
            nums[i] = 0;
            count++;
        }
    }

    qsort(nums, numsSize, 4, cmp);
    return numsSize - count;
}

int dominantIndex(int* nums, int numsSize)
{

    if (numsSize == 1)
        return 0;

    int pos = 0;
    int max = nums[0];
    for (int i = 1; i < numsSize; i++)
    {
        if (max < nums[i])
        {
            max = nums[i];
            pos = i;
        }
    }

    for (int i = 0; i < numsSize; i++)
    {
        if (i == pos)
            continue;
        if (max < 2 * nums[i])
            return -1;
    }

    return pos;
}

int* intersection(int* nums1, int nums1Size, int* nums2, int nums2Size, int* returnSize)
{
    int hash[1001] = { 0 };
    int* arr = (int*)malloc(sizeof(4) * 1000);

    for (int i = 0; i < nums1Size; i++)
    {
        hash[nums1[i]] = 1;
    }

    int count = 0;
    for (int i = 0; i < nums2Size; i++)
    {
        if (hash[nums2[i]] == 1)
        {
            arr[count++] = nums2[i];
            hash[nums2[i]] = 0;
        }
    }

    *returnSize = count;
    return arr;
}